let getTwoArrayDiff = (newArray, old) => {
  let diffArray = [];
  newArray.forEach(item => {
    const { gameuserid } = item;
    let judge = false;
    old.forEach(old => { if (old.gameuserid == gameuserid) judge = true; })
    if (!judge) diffArray.push(item);
  })
  return diffArray;
}

let formatUserName = (userlistArr, usernameArr) => {
  return userlistArr.map((item) => {
    let obj = getUserNameArrItem(item, usernameArr)
    return obj;
  })
}

let getUserNameArrItem = (userItem, usernameArr) => {
  let obj = { ...userItem, formatUserName: null }
  for (let i = 0; i < usernameArr.length; i++) {
    const item = usernameArr[i];
    const { gameuserid, formatUserName } = item;
    if(userItem.gameuserid === gameuserid) obj.formatUserName = formatUserName;
  }
  return obj;
}

module.exports = {
  getTwoArrayDiff,
  formatUserName
};